﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sys.WebRes.Data;

namespace Sys.WebRes.Publish.Areas.Admin.Controllers
{
    public class ResStatusTypeController : Controller
    {
        //
        // GET: /Admin/ResStatusType/

        public ActionResult Index()
        {
            var list = new List<ResStatusType>();

            using (var db = new ResourceSysEntities())
            {
                list = db.ResStatusType.ToList();
            }

            return View(list);
        }

        //
        // GET: /Admin/ResStatusType/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Admin/ResStatusType/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Admin/ResStatusType/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                //using (TransactionScope tran = new TransactionScope())
                {
                    using (var db = new ResourceSysEntities())
                    {
                        int id = db.ResStatusType.Max(p => p.ID);


                        var statusType = new ResStatusType();
                        this.TryUpdateModel<ResStatusType>(statusType);
                        statusType.ID = id + 1;
                        db.AddToResStatusType(statusType);
                        db.SaveChanges();
                    }
                    //tran.Complete();
                }


                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Admin/ResStatusType/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Admin/ResStatusType/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Admin/ResStatusType/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Admin/ResStatusType/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
